using System.Globalization;
using System.Text;
using System.Xml;
using WMM.Tapioca.Taxonomy;
using System.Xml.Linq;

namespace WMM.Tapioca.Linkbase
{
	/// <summary>
    /// XBRL 2.1 Specification 4.11.1.2  
    /// The footnote element is the only resource allowed in footnoteLink elements.
	/// </summary>
    public class Footnote : Resource
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        private XElement thisFootnoteNode;

		/// <summary>
		/// The text of this footnote.
		/// </summary>
		public string Text
		{
			get;
			private set;
		}

		/// <summary>
		/// The culture of this footnote.
		/// </summary>
		public CultureInfo Culture
		{
			get;
			private set;
		}

        internal Footnote(XElement footnoteElement, string label, string documentSource, ExtendedLink extendedLink)
            : base(footnoteElement, label, documentSource, extendedLink)
        {
            thisFootnoteNode = footnoteElement;
            this.Text = thisFootnoteNode.Value;
            this.Culture = null;

            foreach (XAttribute currentAttribute in thisFootnoteNode.Attributes())
            {
                if (currentAttribute.Name.LocalName.Equals("title"))
                    this.Title = currentAttribute.Value;
                else if (currentAttribute.Name.LocalName.Equals("label"))
                    this.Label = currentAttribute.Value;
                else if (currentAttribute.Name.LocalName.Equals("lang"))
                    this.Lang = currentAttribute.Value;
            }
        }

        /// <returns> false </returns>
        public override bool IsLocator()
        {
            return false;
        }

        /// <returns> true </returns>
        public override bool IsResource()
        {
            return true;
        }
    }
}
